package com.smartlink.service;

import com.smartlink.dao.LoginDao;
import com.smartlink.pojo.Student;
import com.smartlink.pojo.Teacher;
import com.smartlink.util.PasswordUtil;

public class LoginService {
	private LoginDao loginDao;

	public void setLoginDao(LoginDao loginDao) {
		this.loginDao = loginDao;
	}

	// 学生登录
	public Student studentLogin(String number) {
		Student student = loginDao.studentLogin(number);
		if (student != null) {
			String value = PasswordUtil.decode(student.getPasswrod());
			Student newStudent = new Student();
			newStudent.setStudentId(student.getStudentId());
			newStudent.setName(student.getName());
			newStudent.setPasswrod(value);
			newStudent.setPhone(student.getPhone());
			return newStudent;
		}
		return null;

	}

	// 教师登录
	public Teacher teacherLogin(String number) {
		Teacher teacher = loginDao.teacherLogin(number);
		if (teacher != null) {
			String value = PasswordUtil.decode(teacher.getPassword());
			Teacher newTeacher = new Teacher();
			newTeacher.setJobNumber(teacher.getJobNumber());
			newTeacher.setName(teacher.getName());
			newTeacher.setPassword(value);
			newTeacher.setPhone(teacher.getPhone());
			return newTeacher;
		}

		return null;
	}

}
